1043C - Smallest Word - CodeForces Solution


constructive algorithms greedy implementation *1500

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

#define _PRINT_ 1
#define _TEST_ 1
#define _SOLVE_ 1

#if defined(DEBUG) && _PRINT_ == 1
#include "debug.h"
#else
#define print(x, ...) 0
#define debug(x, ...) 0
#define verify(x, ...) 0
#endif

using namespace std;

using ll = long long;
constexpr int inf = 1e9;
constexpr ll llinf = 1e18;

/**
 *
 */
void solve() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'a') {
            if (i == n - 1 || s[i + 1] == 'b') {
                ans[i] = 1;
            }
        } else {
            if (i < n - 1 && s[i + 1] == 'a') {
                ans[i] = 1;
            }
        }
    }
    for (auto x : ans) {
        cout << x << " ";
    }
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge